<template>
	<view class="groupactivepay" :style="'padding-bottom:'+ pageSafeArea +'rpx;'">
		<block v-if="showPayPage">
			<view class="fansmeeting_form_topbk_box">
				<image v-if="huodong_id==92" class="fansmeeting_form_topbk" :src="onlinePic+'fansmeeting/pay_bg.png'" mode="widthFix">
				</image>
				<image v-if="huodong_id==160" class="fansmeeting_form_topbk" :src="onlinePic+'fansmeeting/zh/pay_bg_zh.png'" mode="widthFix">
				</image>
			</view>
			<view class="ticket_info_box">
				<view class="ticket_info_title">购票明细</view>
				<view class="mt-20">
					<view class="display_flex">
						<view class="f-13 flex-1">
							{{auditinfo.ticket_experience_name}}-{{auditinfo.ticket_experience_number}}
						</view>
						<view class="f-13">¥{{auditinfo.ticket_experience_price}}</view>
					</view>
					<view v-if="auditinfo.ticket_experience_desc" class="f-11 c-999999 mt-10">
						<view style="line-height: 1.6;">
							<text>{{auditinfo.ticket_experience_desc}}</text>
						</view>
						<view style="line-height: 1.6;color: red;">
							<text>{{auditinfo.ticket_experience_desc_red}}</text>
						</view>
					</view>
				</view>
			</view>
			<view class="pay_type_box" v-if="auditinfo.ticket_experience_status==1">
				<view class="f-15 mb-15">支付方式</view>
				<view class="display_flex">
					<view class="flex-1 display_flex">
						<image class="wechat_icon" :src="onlinePic+'wechat.png'"></image>
						<view class="f-12 ml-5">微信</view>
					</view>
					<view><uni-icons type="circle-filled" size="18" color="#191919"></uni-icons></view>
				</view>
			</view>

			<view v-if="auditinfo.ticket_experience_status==1" class="fansmeeting_pay_bottom_box"
				:style="'padding-bottom:'+ bottomSafeArea +'px;'">
				<view class="display_flex" style="color: #C92359;">
					<view class="f-15">合计：¥{{order_info.money_total}}</view>
					<!-- <view class="f-12">(门票+保险)</view> -->
				</view>
				<view class="group_pay_btn_block mt-15" @click="payFnasMeeting">去支付</view>
			</view>
			<view v-if="auditinfo.ticket_experience_status==2" class="fansmeeting_pay_bottom_box"
				:style="'padding-bottom:'+ bottomSafeArea +'px;'">
				<view class="group_payok_btn_block mt-15">赛道体验券购买已完成</view>
				<view class="mt-5 text-c f-10" style="color: #23AB5E;">赛道体验券与门票同时发放</view>
			</view>
			<view v-if="auditinfo.ticket_experience_status==3" class="fansmeeting_pay_bottom_box"
				:style="'padding-bottom:'+ bottomSafeArea +'px;'">
				<view class="group_wait_btn_block mt-15">赛道体验券购买名额已满</view>
			</view>
		</block>
		<view v-if="auditinfo.ticket_experience_status==2||auditinfo.ticket_experience_status==3"
			class="guide_mask_box"></view>
		<view class="fansmeeting_share_box" v-if="showShareTimeImg">
			<image style="width: 100%;" :src="onlinePic+'fansmeeting/fansmeeting_share_zh.jpg'" mode="widthFix"></image>
		</view>
		<view v-if="isFansPop" class="guide_mask_box" @click="closePopup"></view>
		<view class="fansmeeting_pop_box" v-if="isFansPop">
			<image class="pop_top_img" :src="picUrl+popImg" mode="widthFix"></image>
			<view class="fansmeeting_pop_content_box">
				<view class="fansmeeting_pop_content">
					<text>{{popContent}}</text>
				</view>
				<view class="pd-20">
					<view class="fansmeeting_pop_btn" @click="closePopup">
						我知道了
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		payFnasMeeting,
		getGroupActiveInfo,
		getTYActiveTicketPayInfo,
		getUserGroupActiveAuditInfo
	} from '@/api/motortime.js';
	let app = getApp()
	export default {
		data() {
			return {
				info: '',
				auditinfo: '',
				huodong_id: '',
				project_type: '',
				huodong_club_id: '',
				club_id: '',
				channel: '',
				popImg: '',
				isFansPop: false,
				pay_info: '',
				order_info: '',
				showPayPage: false,
				isSubmit: true,
				popContent: '',
				showShareTimeImg: false,
				picUrl: app.globalData.picUrl,
				onlinePic: app.globalData.onlinePic,
				safeBottom: uni.getSystemInfoSync().safeAreaInsets.bottom > 0 ? true : false,
				pageSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom + 250 : 250,
				bottomSafeArea: uni.getSystemInfoSync().safeAreaInsets.bottom ? uni.getSystemInfoSync().safeAreaInsets
					.bottom : 15
			};
		},
		onShow() {
			if (!uni.getStorageSync('access_token')) {
				uni.navigateTo({
					url: '/pages/login/login'
				})
			} else {
				this.userinfo = uni.getStorageSync('userinfo')
			}
			if (uni.getStorageSync('onload')) {
				this.getGroupActiveInfo()
				this.getUserGroupActiveAuditInfo()
				uni.removeStorage({
					key: 'onload'
				})
			}
			uni.hideShareMenu({
				menus: ['shareAppMessage', 'shareTimeline']
			})
		},
		onLoad(options) {
			uni.showLoading({})
			this.huodong_id = options.huodong_id ? options.huodong_id : ''
			this.huodong_club_id = options.club_id ? options.club_id : ''
			this.channel = options.channel ? options.channel : ''
			this.huodong_join_id = options.huodong_join_id ? options.huodong_join_id : ''
			this.project_type = options.project_type ? options.project_type : ''
			if (uni.getStorageSync('access_token')) {
				this.getGroupActiveInfo()
				this.getUserGroupActiveAuditInfo()
			}
			uni.removeStorage({
				key: 'activeForm'
			})
			if (uni.getStorageSync('Appoptions').scene == 1154) {
				this.showShareTimeImg = true
				uni.hideLoading()
			} else if (uni.getStorageSync('Appoptions').scene == 1155) {
				uni.hideLoading()
				uni.reLaunch({
					url: '/pages/group/groupactiveinfo?huodong_id=' + this.huodong_id +
						'&club_id=' + this
						.huodong_club_id + '&channel=' + this.channel,
				})
			} else {
				this.showShareTimeImg = false
			}
		},
		methods: {
			getTYActiveTicketPayInfo() {
				getTYActiveTicketPayInfo({
					huodong_join_id: this.huodong_join_id,
					project_type: this.project_type
				}).then(res => {
					if (res.state == 1) {
						this.order_info = res.data.order_info
						this.pay_info = res.data.pay_info
						this.showPayPage = true
						uni.hideLoading()
					} else {
						uni.hideLoading()
						this.showPayPage = true
					}
				})
			},
			getUserGroupActiveAuditInfo() {
				getUserGroupActiveAuditInfo({
					huodong_id: this.huodong_id,
					channel: this.channel ? this.channel : ''
				}).then(res => {
					if (res.state == 1) {
						uni.hideLoading()
						this.auditinfo = res.data.info
						this.popImg = res.data.info.festival_popup_img
						if (res.data.info.status != 1) {
							uni.reLaunch({
								url: '/pages/group/groupactiveinfo?huodong_id=' + this.huodong_id +
									'&club_id=' + this
									.huodong_club_id + '&channel=' + this.channel,
							})
						} else {
							if (res.data.info.ticket_experience_status == 1) {
								this.getTYActiveTicketPayInfo()
							} else {
								this.showPayPage = true
								uni.hideLoading()
							}

						}
					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},

			closePopup() {
				this.isFansPop = false
				uni.setStorage({
					key: 'onload',
					data: true,
					success() {
						uni.navigateBack({
							delta: 1
						})
					}
				})

			},
			getGroupActiveInfo() {
				getGroupActiveInfo({
					huodong_id: this.huodong_id
				}).then(res => {
					if (res.state == 1) {
						this.info = res.data.info
						this.club_id = res.data.info.club_id
						var params = {
							event_code: '车友会活动支付',
							path: 'pages/group/groupactivepay',
							event_id: this.huodong_id,
							title: res.data.info.title,
							source_page: '',
							value: this.channel ? this.channel : '',
						}
						app.BurialPoint(params)

					} else {
						uni.showToast({
							title: res.error[0],
							mask: true,
							icon: 'none',
							duration: 1500
						})
					}
				})
			},

			payFnasMeeting() {
				var that = this
				if (that.isSubmit) {
					that.isSubmit = false
					uni.requestPayment({
						timeStamp: that.pay_info.timestamp,
						nonceStr: that.pay_info.nonceStr,
						package: that.pay_info.package,
						signType: that.pay_info.signType,
						paySign: that.pay_info.paySign,
						success(res) {
							that.isSubmit = true
							uni.showToast({
								title: '支付成功',
								icon: 'success',
								duration: 1500,
								mask: true,
								success: function() {
									uni.setStorage({
										key: 'onload',
										data: 'true',
										success() {}
									})
									setTimeout(() => {
										uni.navigateBack({
											delta: 1
										})
									}, 1000);
								}
							})
						},
						fail(res) {
							that.isSubmit = true
							console.log('取消支付或支付失败');
						}
					})
				}

			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #EFF5F8;
	}

	.groupactivepay {
		padding: 30rpx;

		.fansmeeting_form_topbk_box {
			position: absolute;
			top: 0;
			left: 0;
			right: 0;
			z-index: -1;

			.fansmeeting_form_topbk {
				width: 100%;
			}
		}

		.ticket_info_box {
			min-height: 486rpx;
			margin-top: 35%;
			padding: 50rpx 30rpx;
			border-radius: 8rpx;
			background-color: #ffffff;

			.ticket_info_title {
				font-size: 30rpx;
				padding-bottom: 50rpx;
				border-bottom: 1rpx solid #E9E9E9;
			}
		}

		.pay_type_box {
			margin-top: 50rpx;
			padding: 50rpx 30rpx;
			border-radius: 8rpx;
			background-color: #ffffff;

			.wechat_icon {
				width: 38rpx;
				height: 38rpx;
				vertical-align: middle;
			}
		}

		.fansmeeting_pay_bottom_box {
			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			z-index: 1002;
			padding: 30rpx;
			background-color: #ffffff;

			.group_pay_btn_block {
				font-size: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				color: #ffffff;
				padding: 30rpx 0;
				border-radius: 8rpx;
				background-color: #C92359;
			}

			.group_payok_btn_block {
				font-size: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				color: #ffffff;
				padding: 30rpx 0;
				border-radius: 8rpx;
				background-color: #23AB5E;
			}

			.group_wait_btn_block {
				font-size: 30rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				width: 100%;
				color: #ffffff;
				padding: 30rpx 0;
				border-radius: 8rpx;
				background-color: #D0D0D0;
			}
		}
	}
</style>